extends Node
class_name SimpleTest
# 简单的调度系统测试
func _ready() -> void:
	# 等待一帧确保所有系统初始化完成
	await get_tree().process_frame
	
	# 获取battle实例
	var battle = get_tree().get_first_node_in_group("battle")
	if not battle:
		print("❌ 无法找到battle实例")
		return
	
	if not battle.resource_scheduler:
		print("❌ 无法找到resource_scheduler")
		return
	
	print("✅ 调度系统测试开始")
	
	# 验证Player实例
	var player = battle.player
	if not player:
		print("❌ 无法找到player实例")
		return
	
	if not player.stats:
		print("❌ 无法找到player.stats")
		return
	
	print("✅ Player实例验证成功: %s, 当前法力: %d" % [player.name, player.stats.mana])
	
	# 创建一个简单的测试效果
	var test_effect = ScheduledEffect.new()
	test_effect.id = "simple_test_effect"
	test_effect.trigger_type = ScheduledEffect.TriggerType.TURN_COUNT
	test_effect.target_type = ScheduledEffect.TargetType.PLAYER
	test_effect.trigger_turn = 1  # 第1回合触发
	test_effect.is_repeating = false
	test_effect.max_triggers = 1
	
	# 添加一个法力值修改
	var mana_mod = StatModification.new()
	mana_mod.stat_name = "mana"
	mana_mod.modification_type = StatModification.ModificationType.ADD
	mana_mod.value = 2.0
	mana_mod.is_temporary = false
	
	test_effect.stat_modifications.append(mana_mod)
	
	# 添加到调度器
	battle.resource_scheduler.add_scheduled_effect(test_effect)
	print("✅ 简单测试效果已添加到调度器")
	
	# 连接效果触发事件
	battle.resource_scheduler.resource_effect_triggered.connect(_on_test_effect_triggered)

func _on_test_effect_triggered(effect: ScheduledEffect, target: Node) -> void:
	print("🎯 测试效果触发: %s 作用于 %s" % [effect.id, target.name if target else "null"])
	
	# 验证目标
	if not target:
		print("❌ 目标为null，无法应用效果")
		return
	
	if not target is Player:
		print("❌ 目标不是Player类型: %s" % target.get_class())
		return
	
	var player = target as Player
	if not player.stats:
		print("❌ Player没有stats属性")
		return
	
	print("✅ 目标验证成功，当前法力: %d" % player.stats.mana)
	
	# 验证ManaUI连接
	var battle = get_tree().get_first_node_in_group("battle")
	if battle and battle.battle_ui and battle.battle_ui.mana_ui:
		print("🔧 ManaUI连接状态: %s" % (battle.battle_ui.mana_ui.char_stats == player.stats))
	else:
		print("❌ 无法验证ManaUI连接状态")
	
	# 显示效果详情
	for stat_mod in effect.stat_modifications:
		print("  📊 修改: %s +%s" % [stat_mod.stat_name, stat_mod.value])
